Partial Class pages_Customers_Customer : Inherits CPage

#Region "Querystring"
    Public ReadOnly Property CustomerId() As Integer
        Get
            Dim id As Integer = CWeb.RequestInt("customerId")
            If id = Integer.MinValue Then CSitemap.RecordNotFound("Customer", id)
            Return id
        End Get
    End Property
#End Region

#Region "Members"
    Private m_customer As CCustomer
#End Region

#Region "Data"
    Public ReadOnly Property [Customer]() As CCustomer
        Get
            If IsNothing(m_customer) Then
                Try
                    m_customer = New CCustomer(CustomerId)
                Catch
                    CSitemap.RecordNotFound("Customer", CustomerId)
                End Try                   
            End If
            Return m_customer
        End Get
    End Property
#End Region

#Region "Event Handlers - Page"
    Protected Overrides Sub PageInit()
        MyBase.PageInit()

        AddMenuSide("Customer Orders", CSitemap.OrdersForCustomer(CustomerId))
        'AddMenuSide("Customer Reminders", CSitemap.RemindersForCustomer(CustomerId))
        AddMenuSide("Customer Payments", CSitemap.PaymentsForCustomer(CustomerId))
    End Sub
    Protected Overrides Sub PageLoad()
        With Me.Customer
            txtCustomerName.Text = .CustomerName
            txtCustomerEmail.Text = .CustomerEmail

            lnkOrders.Text = CUtilities.CountSummary(.OrdersCount, "order", "none")
            lnkOrders.NavigateUrl = CSitemap.OrdersForCustomer(.CustomerId)
            lnkPaid.Text = CTextbox.SetMoney(.TotalPaid)
            lnkSales.Text = CTextbox.SetMoney(.TotalSales)
        End With
    End Sub
#End Region

    Protected Sub btnUpdate_Click(sender As Object, e As System.EventArgs) Handles btnUpdate.Click
        Customer.CustomerName = txtCustomerName.Text
        Customer.CustomerEmail = txtCustomerEmail.Text
        Customer.Save()
        Response.Redirect(Request.RawUrl)
    End Sub
End Class
